#include <bits/stdc++.h>
using namespace std;
typedef long long in;
const in M=1e6+10;
in t,n,a[M];
in k=0;
in s[M]={0},b[M]={0};
void turn(int x)
{
    in y=n-1;
    while(x>0){
        b[y]=x%2;
        y--;
        x/=2;
    }
}
in mark()
{
    int sum=0;
    for(in i=1;i<n;i++){
        for(in j=i-1;j>=0;j--){
            if(b[i]==b[j]){
                if(a[i]==a[j]){
                    sum+=a[i];
                }
                break;
            }
        }
    }
    return sum;
}
in mi(int p)
{
    in num=1;
    for(in i=0;i<p;i++){
        num*=2;
    }
    return num;
}
void f2()
{
    in i=0;
    for(i=0;i<n;i++) b[i]=0;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    for(in i=0;i<t;i++){
        cin>>n;
        k=0;
        for(in j=0;j<n;j++){
            cin>>a[j];
            b[j]=0;
        }
        in ans=0;
        for(k=0;k<mi(n);k++){
            f2();
            turn(k);
            ans=max(ans,mark());
        }
        cout<<ans<<endl;
    }
    return 0;
}
